//
//  HomeADTableCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/7/25.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit
import SDWebImage

class HomeADTableCell: BaseTableViewCell {
    @IBOutlet weak var bottomConstr: NSLayoutConstraint!
    
    @IBOutlet weak var imgView: UIImageView!
    
    @IBOutlet weak var imageHonstr: NSLayoutConstraint!
    @IBOutlet weak var inditor: UIActivityIndicatorView!
    
    
    var model : HomeOneGroup?{
        
        didSet{
            
            guard let imageCach = SDWebImageManager.shared().imageCache else {
                
                imageHonstr.constant = 90.0

                return
                
            }
            
            guard let image = imageCach.imageFromDiskCache(forKey: model!.image) else {
                
                imageHonstr.constant = 90.0

                return
            }
            
                 
            imageHonstr.constant = KScreenW / (image.size.width / image.size.height)

            imgView.image = image

        

            
        }
        
        
    }
    

    override func awakeFromNib() {
        super.awakeFromNib()
        contentView.backgroundColor = UIColor.lineGray()
        bottomConstr.constant = -8

        // Initialization code
    }

    @IBAction func btnDidTap(_ sender: UIButton) {
        
       jumpVC(type: model?.type, data: model?.data)
        
    }
    
    
    
    
    func jumpVC(type : String?,data : String?) {
        
        
        if type == "keyword" {
            
            let temp = GoodsListController()
            
            temp.keyword = data
            
            viewController().navigationController?.pushViewController(temp, animated: true)
            
        } else {
            
            if type == "url" {
                
                if data!.contains("mall.xjscvip.com") {
                    
                    let temp = UpLoadIconController()
                    
                    
                    temp.urlStr = data ?? ""
                    
                    
                    viewController().navigationController?.pushViewController(temp, animated: true)
                    
                } else {
                    
                    let temp = UpLoadIconController()
                    
                    temp.hiddenBar = false
                    
                    temp.urlStr = data ?? ""
                    
                    
                    viewController().navigationController?.pushViewController(temp, animated: true)
                    
                }
                
                
                
            } else if type == "goods"{
                
                let temp = GoodsDetailController()
                
                temp.urlStr = data ?? ""
                
                viewController().navigationController?.pushViewController(temp, animated: true)
                
            }
            
            
            
        }
        
        
        
    }
    
    
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
